from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-05 14:04:06.405274
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 05, Aug, 2022
Time: 14:04:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.0368
Nobs: 739.000 HQIC: -50.3814
Log likelihood: 9348.48 FPE: 1.06099e-22
AIC: -50.5977 Det(Omega_mle): 9.40100e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297020 0.055760 5.327 0.000
L1.Burgenland 0.107722 0.036928 2.917 0.004
L1.Kärnten -0.106853 0.019572 -5.460 0.000
L1.Niederösterreich 0.206745 0.077044 2.683 0.007
L1.Oberösterreich 0.109049 0.075294 1.448 0.148
L1.Salzburg 0.254297 0.039463 6.444 0.000
L1.Steiermark 0.042410 0.051489 0.824 0.410
L1.Tirol 0.108554 0.041773 2.599 0.009
L1.Vorarlberg -0.062267 0.035922 -1.733 0.083
L1.Wien 0.048323 0.066574 0.726 0.468
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058031 0.116521 0.498 0.618
L1.Burgenland -0.031972 0.077168 -0.414 0.679
L1.Kärnten 0.047046 0.040898 1.150 0.250
L1.Niederösterreich -0.175995 0.160997 -1.093 0.274
L1.Oberösterreich 0.407285 0.157341 2.589 0.010
L1.Salzburg 0.287840 0.082465 3.490 0.000
L1.Steiermark 0.107999 0.107596 1.004 0.316
L1.Tirol 0.311334 0.087292 3.567 0.000
L1.Vorarlberg 0.025354 0.075066 0.338 0.736
L1.Wien -0.029514 0.139120 -0.212 0.832
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188787 0.028618 6.597 0.000
L1.Burgenland 0.090172 0.018953 4.758 0.000
L1.Kärnten -0.008864 0.010045 -0.882 0.378
L1.Niederösterreich 0.259873 0.039542 6.572 0.000
L1.Oberösterreich 0.139113 0.038644 3.600 0.000
L1.Salzburg 0.045574 0.020254 2.250 0.024
L1.Steiermark 0.021516 0.026426 0.814 0.416
L1.Tirol 0.093129 0.021439 4.344 0.000
L1.Vorarlberg 0.055532 0.018437 3.012 0.003
L1.Wien 0.116308 0.034169 3.404 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107982 0.029065 3.715 0.000
L1.Burgenland 0.045752 0.019249 2.377 0.017
L1.Kärnten -0.013995 0.010202 -1.372 0.170
L1.Niederösterreich 0.189487 0.040159 4.718 0.000
L1.Oberösterreich 0.302556 0.039247 7.709 0.000
L1.Salzburg 0.109793 0.020570 5.338 0.000
L1.Steiermark 0.104512 0.026839 3.894 0.000
L1.Tirol 0.105700 0.021774 4.854 0.000
L1.Vorarlberg 0.068534 0.018725 3.660 0.000
L1.Wien -0.021120 0.034702 -0.609 0.543
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125708 0.052966 2.373 0.018
L1.Burgenland -0.049959 0.035078 -1.424 0.154
L1.Kärnten -0.040696 0.018591 -2.189 0.029
L1.Niederösterreich 0.169629 0.073183 2.318 0.020
L1.Oberösterreich 0.139809 0.071521 1.955 0.051
L1.Salzburg 0.288933 0.037485 7.708 0.000
L1.Steiermark 0.035735 0.048909 0.731 0.465
L1.Tirol 0.163103 0.039679 4.111 0.000
L1.Vorarlberg 0.100966 0.034122 2.959 0.003
L1.Wien 0.068801 0.063238 1.088 0.277
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055492 0.042089 1.318 0.187
L1.Burgenland 0.039332 0.027874 1.411 0.158
L1.Kärnten 0.051075 0.014773 3.457 0.001
L1.Niederösterreich 0.217962 0.058154 3.748 0.000
L1.Oberösterreich 0.295966 0.056833 5.208 0.000
L1.Salzburg 0.043917 0.029787 1.474 0.140
L1.Steiermark 0.001237 0.038865 0.032 0.975
L1.Tirol 0.143214 0.031531 4.542 0.000
L1.Vorarlberg 0.071972 0.027115 2.654 0.008
L1.Wien 0.080629 0.050251 1.605 0.109
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173128 0.050326 3.440 0.001
L1.Burgenland -0.002370 0.033330 -0.071 0.943
L1.Kärnten -0.062552 0.017664 -3.541 0.000
L1.Niederösterreich -0.078266 0.069536 -1.126 0.260
L1.Oberösterreich 0.190521 0.067957 2.804 0.005
L1.Salzburg 0.057953 0.035617 1.627 0.104
L1.Steiermark 0.234664 0.046472 5.050 0.000
L1.Tirol 0.498465 0.037702 13.221 0.000
L1.Vorarlberg 0.045183 0.032422 1.394 0.163
L1.Wien -0.054463 0.060087 -0.906 0.365
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160697 0.058026 2.769 0.006
L1.Burgenland -0.008186 0.038429 -0.213 0.831
L1.Kärnten 0.065766 0.020367 3.229 0.001
L1.Niederösterreich 0.205255 0.080174 2.560 0.010
L1.Oberösterreich -0.067678 0.078353 -0.864 0.388
L1.Salzburg 0.208660 0.041066 5.081 0.000
L1.Steiermark 0.122384 0.053581 2.284 0.022
L1.Tirol 0.073276 0.043470 1.686 0.092
L1.Vorarlberg 0.120407 0.037382 3.221 0.001
L1.Wien 0.120889 0.069279 1.745 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359639 0.033327 10.791 0.000
L1.Burgenland 0.007179 0.022072 0.325 0.745
L1.Kärnten -0.023660 0.011698 -2.023 0.043
L1.Niederösterreich 0.215138 0.046048 4.672 0.000
L1.Oberösterreich 0.199260 0.045003 4.428 0.000
L1.Salzburg 0.043650 0.023587 1.851 0.064
L1.Steiermark -0.013166 0.030775 -0.428 0.669
L1.Tirol 0.104789 0.024967 4.197 0.000
L1.Vorarlberg 0.070910 0.021470 3.303 0.001
L1.Wien 0.038267 0.039791 0.962 0.336
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039448 0.139652 0.191511 0.151102 0.117494 0.103155 0.063286 0.216561
Kärnten 0.039448 1.000000 -0.007583 0.132364 0.039244 0.094354 0.432990 -0.053940 0.097352
Niederösterreich 0.139652 -0.007583 1.000000 0.333882 0.141930 0.292628 0.095951 0.179845 0.313248
Oberösterreich 0.191511 0.132364 0.333882 1.000000 0.229215 0.324802 0.176106 0.166022 0.261043
Salzburg 0.151102 0.039244 0.141930 0.229215 1.000000 0.142378 0.112937 0.145546 0.124021
Steiermark 0.117494 0.094354 0.292628 0.324802 0.142378 1.000000 0.146143 0.137486 0.071439
Tirol 0.103155 0.432990 0.095951 0.176106 0.112937 0.146143 1.000000 0.112352 0.142872
Vorarlberg 0.063286 -0.053940 0.179845 0.166022 0.145546 0.137486 0.112352 1.000000 -0.000755
Wien 0.216561 0.097352 0.313248 0.261043 0.124021 0.071439 0.142872 -0.000755 1.000000